# Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.10)

set(MEMTESTS_JS_SOURCES
    weakContainers.js
)

panda_ecmascript_add_gtest(
    NO_CORES
    NAME arkruntime4ecmascript_mem_weak_tests
    SOURCES
        weak_containers_test.cpp
    LIBRARIES
        arkruntime arkassembler
    SANITIZERS
        ${PANDA_SANITIZERS_LIST}
)

foreach(JS_SOURCE ${MEMTESTS_JS_SOURCES})
    string(REGEX REPLACE "[.]js$" ".abc" ABC_FILE ${JS_SOURCE})
    add_custom_command(
        OUTPUT ${ABC_FILE}
        COMMAND ${PANDA_RUN_PREFIX} $<TARGET_FILE:es2panda> ${CMAKE_CURRENT_SOURCE_DIR}/${JS_SOURCE} --output ${ABC_FILE}
    )
    add_custom_target(es2panda_convert_${JS_SOURCE}
                      DEPENDS ${ABC_FILE})
    # TODO(maksenov): target with _gtests postfix for test run is hidden now.
    #                 Need to add interface to specify test run dependencies
    add_dependencies(arkruntime4ecmascript_mem_weak_tests_gtests es2panda_convert_${JS_SOURCE})
endforeach()
